﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[proc_AB_List_Stored]
(
	@Iid INT,
	@StartDate VARCHAR(20)
)	
AS
BEGIN
	SELECT a.Companyname,a.Productname,
	IsNull((Select b.je From AB_List b Where b.Iid=a.id And Convert(varchar(10),b.UpTime,120)=@StartDate And AB_Type=0),0) As je,
	IsNull((Select Top 1 c.ye From AB_List c Where c.Iid=a.id And Convert(varchar(10),c.UpTime,120)<=@StartDate And AB_Type=0 Order By c.UpTime Desc),0) As ye,
	IsNull((Select d.Items From AB_List d Where d.Iid=a.id And Convert(varchar(10),d.UpTime,120)=@StartDate And AB_Type=0),0) As Items
	FROM AB_Interface a
	WHERE syzh =@Iid	
END